﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

namespace Phone.Framework.Data
{
   
    public class AppSettings<T>
    {
        public static string AppSettingsKey = "AppSettings";

        private static IsolatedStorageSettings set = IsolatedStorageSettings.ApplicationSettings;

        private static T settingObj = default(T);

        
        public static void CreateInstance(T instance)
        {
            settingObj = instance;
            Clear();
        }

        public static void SaveAppSetting()
        {
            set[AppSettingsKey] = settingObj;
            set.Save();
        }

        public static T GetAppSetting()
        {
            if (settingObj == null)
                settingObj = (T)set[AppSettingsKey];
            return settingObj;
        }

        public static void Clear()
        {
            set.Remove(AppSettingsKey);
            set.Save();
        }
    }
}
